package com.parking.gateway.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

@Component
public class RedisUtil {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void set(String key,String value){
        stringRedisTemplate.opsForValue().set(key,value);
    }

    public void set(String key,String value,Long expire){
        stringRedisTemplate.opsForValue().set(key,value,expire, TimeUnit.SECONDS);
    }

    public String get(String key){
        return stringRedisTemplate.opsForValue().get(key);
    }

    public void del(String... key){
        stringRedisTemplate.delete(Arrays.asList(key));
    }

    public boolean exist(String key){
        return Boolean.TRUE.equals(stringRedisTemplate.hasKey(key));
    }

    public void incr(String key){
        stringRedisTemplate.opsForValue().increment(key);
    }
}
